package com.ywl5320.myplayer.util;

import android.media.MediaCodecList;
import android.os.Build;
import android.support.annotation.RequiresApi;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * Created by Chen qin lang on 2018/7/17.
 */
public class WlCodecSupportUtil {
    public static Map<String,String> map = new HashMap<>();

    static {
        map.put("h264", "video/avc");
    }

    public static String findSupportCodec(String codecname) {
        if (map.containsKey(codecname)) {
            return map.get(codecname);
        }

        return "";

    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public static boolean isSupportCodec(String codecname) {
        int count = MediaCodecList.getCodecCount();
        boolean isSupport = false;
        for (int i = 0; i < count; i++) {
            String[] supportedTypes = MediaCodecList.getCodecInfoAt(i).getSupportedTypes();
            for (int j = 0; j < supportedTypes.length; j++) {
                if (supportedTypes[j].equals(findSupportCodec(codecname))) {
                    isSupport = true;
                    break;
                }
            }
            if (isSupport) {
                break;
            }
        }
        return isSupport;
    }
}
